package cn.myschool.service;

import cn.myschool.dao.StudentDao;
import cn.myschool.entity.Student;
import cn.myschool.pojo.ExamResult2;
import cn.myschool.pojo.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
@Transactional
public class StudentService {
    public static final int PAGE_SIZE = 10;

    @Resource
    private StudentDao mapper;
//    public Student get(long stuno){
//
//    }
//
    public int add(Student st){
        return mapper.add(st);
    }
//
//
//
//    //根据学号修改信息
//    int update(Student student);
//    //根据学号删除学生
//    int del(long id);

    //多条件搜索，返回Page
    public Page<Student> search(String wechat, String qq, String sname, Date start, Date end, int pageNo) {

        List<Student> list = mapper.search(wechat, qq, sname, start, end, pageNo, PAGE_SIZE);
        int total = mapper.searchTotal(wechat, qq, sname, start, end);
        return new Page<>(pageNo, PAGE_SIZE, total, list);


    }

    //按照 微信号,qq号,姓名,模糊查找学生的功能，加上分页
    public List<Student> search(String wechat, String qq, String sname, Date start, Date end, int pageNo, int pageSize) {

        List<Student> list = mapper.search(wechat, qq, sname, start, end, pageNo, pageSize);

        return list;


    }

    public int searchTotal(String wechat, String qq, String sname, Date start, Date end) {


        return mapper.searchTotal(wechat, qq, sname, start, end);


    }


    public Page<ExamResult2> findScore(long stuno, int pageNo) {
        pageNo = pageNo < 1 ? 1 : pageNo;

        List<ExamResult2> list = mapper.findScore(stuno, pageNo, PAGE_SIZE);
        int scoreTotal = mapper.findScoreTotal(stuno);
        return new Page<ExamResult2>(pageNo, PAGE_SIZE, scoreTotal, list);


    }

    public Student get(long stuno) {

        return mapper.get(stuno);

    }

    public int update(Student s) {
        return mapper.update(s);
    }

    public int del(long stuno) {
        return mapper.del(stuno);
    }
}
